package com.woniu.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


@Component
public class EnergyRabbitConfig {
    public static String QueueName = "energy_queue";
    public static String ExchangeName = "energy_exchange";
    @Bean("energy_queue")
    public Queue getQueue(){
        return QueueBuilder.durable(QueueName).build();
    }

    @Bean("energy_exchange")
    public Exchange getExchange(){
        return ExchangeBuilder.topicExchange(ExchangeName).durable(true).build();
    }

    @Bean("energy_binding")
    public Binding getBinding(@Qualifier("energy_queue") Queue queue,@Qualifier("energy_exchange")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("energy.add").noargs();
    }

    public static String QueueName1 = "PHApplication_queue";
    public static String ExchangeName1 = "PHApplication_exchange";
    @Bean("PHApplication_queue")
    public Queue getQueue1(){
        return QueueBuilder.durable(QueueName1).build();
    }

    @Bean("PHApplication_exchange")
    public Exchange getExchange1(){
        return ExchangeBuilder.topicExchange(ExchangeName1).durable(true).build();
    }

    @Bean("PHApplication_binding")
    public Binding getBinding1(@Qualifier("PHApplication_queue")Queue queue,@Qualifier("PHApplication_exchange")Exchange exchange){
//        return new Binding(QueueName, Binding.DestinationType.QUEUE,ExchangeName,"PHApplication.add",null);
        return BindingBuilder.bind(queue).to(exchange).with("PHApplication.add").noargs();
    }
}
